<?php    
header('Content-type: application/xls');
$tenfile='sdthuoc'.date('Y-m-d_h-m-s').'.xls';
header("Content-Disposition:attachment;filename=$tenfile");

?>
<?php $socot = count($noidungs);
$socot1=$socot+1;?>
<table><tr><?php
	echo '<td colspan="'.$socot1.'" align="center">';
?><strong><font size="+2">THÔNG TIN PHIẾU ĐIỀU TRA</font></strong></td></tr></table>
<table border="1">
	
	<tr>	
        <td colspan="2"><strong>Ngày điều tra:</strong>
        </td>
        <td><?php 
				echo date('m-d-Y', strtotime($phieu['PhieuDt']['NGAY'])); 
				echo '&nbsp;';
				echo '(Lần thứ: '.$phieu['PhieuDt']['LAN'].')';
			?></td>
	</tr>
    <tr>
    <td colspan="2"><strong>Ngày sau sạ:</strong></td><td>	<?php echo $phieu['Nss']['TEN_NSS']; ?></td>		
			
	
    </tr>
    <tr>	 <td colspan="2"><strong>Cán bộ điều tra:</strong></td><td>	<?php echo $phieu['Canbo']['HOTEN']; ?></td>	
		
	</tr>
    
   
  
    </table>		

<div class="phieuDts form">
<?php
//import ham javascript
	echo $javascript->link('custom_scripts.js');
?>

<?php echo $form->create(null, array('url'=>'dienthongtin/'.$phieu['PhieuDt']['id'].'/'.$loai['LoaiDt']['id'],'onSubmit'=>'return validate()'));?>

	<fieldset>
		<?php 
			echo $form->hidden('phieu.id', array('value'=>$phieu['PhieuDt']['id']));
		?>
 		<legend><font size="+3"><strong><?php echo $loai['LoaiDt']['TEN_LOAI'];?></strong></font></legend>
 		<div class="view">
		<table border="1">
			<?php
				//$socot = count($noidungs);
				$sodong = count($diems);
				$sonhom = count($doituongs);
				$hang = 0;
				$ikq = 0;
				$edit = (!empty($ketquas))?true:false;
			?>
			<tr>
				<th><?php echo 'Điểm';?></th>
			<?php
			for($ind = 0; $ind < $socot; $ind++){//$noidungs as $noidung){
			?>	
				<th>
					<?php
					echo $noidungs[$ind]['NdDt']['DG_ND'];
					?>
				</th>
			<?php } ?>
			</tr>
			<?php
			for($idt = 0; $idt < $sonhom; $idt++){//$doituongs as $doituong){
			?>
			<tr>
				<td <?php echo 'colspan='.($socot + 1);?>><b>
					<?php echo $doituongs[$idt]['Doituong']['TEN_DT'];?>
				</b></td>
			</tr>
				<?php
				$i = 0;
				for($idi = 0; $idi < $sodong; $idi++){//$diems as $diem){
					$class = null;
					/*if ($i++ % 2 == 0) {
						$class = ' class="altrow"';
					}
					echo '<tr'.$class.'>';*/
					echo '<tr>';
					echo '<td>';
					echo $diems[$idi]['DiemDt']['DIEM'];
					echo '</td>';
					for($j = 0; $j < $socot; $j++){
						echo '<td>';
						$kq = 0;
						if($edit){
							$kq = $ketquas[$ikq]['Ketqua']['KETQUA'];
							$ikq++;
							if(!isset($ketquas[$ikq]['Ketqua']['id'])) $edit = false;// trường hợp có nhiều ô nhập liệu hơn kết quả đã nhập
						}//hang->doituong, j->cot->stt
						echo $kq;
						echo '</td>';
					}
					echo '</tr>';
					$hang++;
				}
				?>
			<?php
			}
			?>			
		</table>
		</div>
	</fieldset>
<?php echo $form->end();?>
</div>